#include "dynamicArray.h"  
DA * initList(){
     DA* header = (DA *)malloc(sizeof(DA));
     ERROE_CHECK(NULL,header,"malloc");
    header->data = (type *)malloc(sizeof(type));
    ERROE_CHECK(NULL,header->data,"malloc");
    header->index = -1;
    header->data_size = 1;
    printf("11111\n");
    return header;
}

void addList(DA * header,int val){
    if (header->index+1 == header->data_size)
    {
       int new_size = header->data_size*2;
        header->data = (type *)realloc(header->data,new_size*sizeof(type));
        if (NULL == header->data)
        {
            perror("realloc");
            exit(1);
        }
        header->data_size = new_size;
       
    }
     header->data[++header->index] = val;
    
}
void showList(DA *header){
    for (size_t i = 0; i <= header->index; i++)
    {
        printf("%d ",header->data[i]);
    }
    puts("");

}
void delList(DA * header,int index){
    if (header->index+1 <= header->data_size / 2)
    {
       int new_size = header->data_size / 2;
        header->data = (type *)realloc(header->data,new_size*sizeof(type));
        if (NULL == header->data)
        {
            perror("realloc");
            exit(1);
        }
        header->data_size = new_size;   
    }
    if (index <= header->index)
    {
        for (size_t i = index; i < header->index; i++)
        {
            header->data[i] = header->data[i+1];
        }
        header->index--;
    }
    
}
